<?php
namespace app\admin\controller;
use app\model\Exam as ExamModel;
class Exam extends Common
{
    public function list1()
    {
        return $this->fetch();
    }

    public function uploadfile()
    {
        $name=session('username');
        $file=request()->file('file');
        $info=$file->validate(['ext'=>'zip,rar,pdf,docx,doc,txt'])->move('./static/uploads/'.$name.'/','');
        if($info){
            return['code'=>0,'msg'=>$info->getSaveName()];
        }else{
            return['code'=>1,'msg'=>$file->getError()];
        }
    }

    public function getExamData()
    {

        $page = request()->param('page');//默认1
        $limit = request()->param('limit');//默认10
        $val=request()->param('value');

        $start=($page-1)*$limit;   
        if($val =='') { 
        $userinfo=ExamModel::limit($start,$limit)->order('create_time','desc') ->select();
        $count=count(ExamModel::select());  
        }else{      
            $userinfo=ExamModel::withSearch(['examname'],['examname'=>$val])->limit($start,$limit)->order('create_time','asc') ->select();
            $count=count(ExamModel::withSearch(['examname'],['examname'=>$val])->select());  
        }
        $msg=[
            'code'=>0,  
            'msg'=>'查询成功',
            'data'=>$userinfo,
            'count'=>$count,
        ];
        echo json_encode($msg); 
        die;
    }

  
}
